package com.runa.rccprotocol.dto.guangda;

import com.runa.persistence.DateUtil;

/**
 * 2024/7/3 11:25
 * zhangYB
 */
public enum GdFmuControl {
    REGISTER((byte) 0x02, (short)4),
    REGISTER_ACK((byte) 0x82, (short)7),
    HEARTBEAT((byte) 0x01, (short)7),
    HEARTBEAT_ACK((byte) 0x81, (short)7),
    READ((byte) 0x1B, (short)6),
    READ_ONE((byte) 0x1C, (short)7),
    READ_ONE_RESPONSE((byte) 0x9C, (short)0),
    READ_RESPONSE((byte) 0x9B, (short)0),
    VALVE_CONTROL_RESPONSE((byte) 0xC8, (short)0),
    VALVE_CONTROL_RESPONSE2((byte) 0x88, (short)0);

    private byte value;

    private short dataLen;

    GdFmuControl(byte value, short dataLen) {
        this.value = value;
        this.dataLen = dataLen;
    }

    public byte getValue() {
        return value;
    }

    public short getDataLen() {
        return dataLen;
    }

    public byte[] getData() {
        switch(this) {
            case REGISTER_ACK:
            case HEARTBEAT_ACK:
                return DateUtil.getNowTimeBytes();
        }
        return null;
    }

    public static GdFmuControl valueOf(byte value) {
        for (GdFmuControl gdFmuControl : values()) {
            if (gdFmuControl.getValue() == value) {
                return gdFmuControl;
            }
        }
        return null;
    }



}
